<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <!-- <el-form-item label="加工厂" class="myform-item">
          <el-select v-model="form.supplier_id" placeholder="请选择" clearable>
            <el-option
              v-for="item in factoryList"
              :key="item.supplier_id"
              :label="item.factory_name"
              :value="item.supplier_id"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="款号" class="myform-item">
          <el-input v-model="form.type_no" placeholder="请输入款号" clearable @keyup.enter.native="onSearch"></el-input>
        </el-form-item>
        <el-form-item label="核价单编码" class="myform-item">
          <el-input v-model="form.pricing_number" placeholder="请输入核价单编码" clearable @keyup.enter.native="onSearch"></el-input>
        </el-form-item>
        
        <el-form-item label="核价用途" class="myform-item">
          <el-select v-model="form.valuation_purpose" placeholder="请选择" clearable @keyup.enter.native="onSearch">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态" class="myform-item">
          <el-select v-model="form.s_status" placeholder="请选择" clearable @keyup.enter.native="onSearch">
            <el-option
              v-for="item in statusoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px" class="myform-item">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <div style="margin:20px 0">
      <el-button type="primary" @click="onUpdate">更新核价单</el-button>
      <span style="margin-left:30px">最后更新日期：{{ savetime }}</span>
    </div>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="创建人" align="center" prop="adduser"></el-table-column>
      <el-table-column label="核价单编码" align="center" prop="pricing_number"></el-table-column>
      <el-table-column label="款号" align="center" prop="type_no"></el-table-column>
      <el-table-column label="核价用途" align="center" prop="valuation_purpose"></el-table-column>
      <el-table-column label="创建时间" align="center" prop="addtime"></el-table-column>

      <el-table-column label="状态" align="center" prop="s_status">
        <template slot-scope="{ row }">
          <div
            :style="{
              color: row.s_status == 0 ? '#67C23A' : row.s_status == 1 ? 'red' : '',
            }"
          >
            {{
              row.s_status == 0
                ? "正常"
                : row.s_status == 1 ? "锁定" : ""
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="成衣成本加价总价" align="center" prop="garment_cost_plus_total"></el-table-column>
      <el-table-column label="绣花成本加价总价" align="center" prop="embroider_cost_plus_total"></el-table-column>
      <el-table-column label="成本加价总价" align="center" prop="cost_plus_total"></el-table-column>
      <el-table-column label="备注" align="center" prop="comment" width="400px"></el-table-column>
       <el-table-column label="审核时间" align="center" prop="examinetime"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" @click="onLook(row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminPricingGetPricingGetPricingOrder"
    />
  </div>
</template>

<script>
import {
  postAdminPricingGetPricingGetPricingOrder,
  postHomeCodeGetFactory,
  postAdminPricingGet_shujia_PricingExamineOrder
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      auditdialogVisible: false,
      isTrue: false, // 是否带参数
      factoryList: [],
      savetime: "",
      statusoptions: [
        {
          value: "",
          label: "全部",
        },
        {
          value: 0,
          label: "正常",
        },
        {
          value: 1,
          label: "锁定",
        },
      ],
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "大货核价",
          label: "大货核价",
        },
        {
          value: "过审核价",
          label: "过审核价",
        },
        {
          value: "成本预估价",
          label: "成本预估价",
        },
        {
          value: "实付核价",
          label: "实付核价",
        },
      ],
      form: {
        // supplier_id: "",
        type_no: "",
        pricing_number:"",
        s_status: "",
        valuation_purpose: "",
        page: 1,
        size: 10,
      },
      auditform: {
        status: 1,
      },
      tableData: [],
      total: 1,
      // 选中
      editForm: {
        id: "",
        pay_pricing_number: "",
      },
    };
  },
  activated() {
    let form = this.form;
    if (this.$route.query.id) {
      this.form.type_no = this.$route.query.type_no;
      this.editForm.id = this.$route.query.id;
      this.isTrue = true;
    } else {
      this.isTrue = false;
    }
    this.postHomeCodeGetFactory();
    this.postAdminPricingGetPricingGetPricingOrder(form);
  },
  methods: {
    // 更新核价单
    onUpdate() {
      this.loading = true;
      let form = this.form;
      postAdminPricingGet_shujia_PricingExamineOrder().then((res) => {
        this.postAdminPricingGetPricingGetPricingOrder(form);
      }).catch(err=>this.loading = false);
    },
    // 加工厂列表
    postHomeCodeGetFactory() {
      let obj = {
        page: 1,
        size: 1000,
      };
      postHomeCodeGetFactory(obj).then((res) => {
        this.factoryList = res.data;
      });
    },
    // 查看
    onLook(id) {
      this.$router.push({name:"NuclearpriceListDetail",query:{id}})
    },
    // 采购列表
    async postAdminPricingGetPricingGetPricingOrder(data) {
      this.loading = true;
      this.form = data;
      postAdminPricingGetPricingGetPricingOrder(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.savetime = res.savetime;
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminPricingGetPricingGetPricingOrder(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
